﻿package mortal.game.view.mainUI.smallMap
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import extend.language.*;
    import fl.data.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.game.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.model.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.map3D.AstarAnyDirection.data.*;
    import mortal.game.scene3D.map3D.sceneInfo.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.utils.*;
    import mortal.game.view.copy.petBreak.*;
    import mortal.game.view.mainUI.smallMap.view.data.*;
    import mortal.game.view.mainUI.smallMap.view.typeIconDataParser.*;
    import mortal.mvc.core.*;

    public class SmallMapCache extends Object
    {
        private var myShowTypes:Array;
        private var _dropName:Array;
        private var showTypes:Array;
        public var worldDatas:Array;
        public const regionDatas_0:Array;
        public var allRegions:Array;
        private var _allForceEntityPoints:Array;
        private var _paths:Array;
        private var _shortMapEntitys:Array;
        private var _lastFisrtDistance:int = 1000000;
        private var _customMapPointDatas:Array;
        public static const MapRegionRelationConst:Object = {90000:10005, 90001:10005, 90002:10005, 90003:10005, 90004:10005, 90005:10005, 90006:10005, 90007:10005, 90008:10005, 90009:10005};

        public function SmallMapCache()
        {
            this.myShowTypes = [{icon:ImagesConst.MapPoint_PassPoint, name:Language.getString(20059), type:SmallMapShowType.MapShowTypePassPoint}, {icon:ImagesConst.MapPoint_Boss, name:Language.getString(20060), type:SmallMapShowType.MapShowTypeBoss}, {icon:ImagesConst.MapPoint_TaskNpc, name:"NPC", type:SmallMapShowType.MapShowTypeTaskNpc}, {icon:ImagesConst.MapPoint_TaskEScort, name:Language.getString(21287), type:SmallMapShowType.MapShowTypeTaskEScort}, {icon:ImagesConst.MapPoint_TaskLoop, name:Language.getString(21288), type:SmallMapShowType.MapShowTypeTaskLoop}, {icon:ImagesConst.MapPoint_TaskLueMo, name:Language.getString(21289), type:SmallMapShowType.MapShowTypeTaskLueMo}, {icon:ImagesConst.MapPoint_TaskMining, name:Language.getString(21290), type:SmallMapShowType.MapShowTypeTaskMining}, {icon:ImagesConst.MapPoint_Jump, name:Language.getString(21291), type:SmallMapShowType.MapShowtypeJumpPoint}, {icon:ImagesConst.MapPoint_ChangeCareer, name:Language.getString(21292), type:SmallMapShowType.MapShowTypeChangeCareer}];
            this._dropName = ["", Language.getString(21293), Language.getString(21294), Language.getString(21299), Language.getString(21296), Language.getString(21297), Language.getString(21298), Language.getString(21299), Language.getString(21300), Language.getString(21301), Language.getString(21302), Language.getString(21303)];
            this.worldDatas = [new SmallMapWorldRegionData(-1, "regionDatas_0", 100, 100, 24, 100, Language.getString(21306), true, 0, "mapRegion1Bg")];
            this.regionDatas_0 = [new SmallMapWorldRegionData(10000, "smallMapRegion1", 525, 185, 25, 100, Language.getString(21307), true, 0, "mapRegion1Bg"), new SmallMapWorldRegionData(10001, "smallMapRegion1", 545, 314, 10, 50, Language.getString(21308)), new SmallMapWorldRegionData(10002, "smallMapRegion1", 293, 249, 17, 120, Language.getString(21309)), new SmallMapWorldRegionData(10003, "smallMapRegion1", 408, 184, 21, 80, Language.getString(21310)), new SmallMapWorldRegionData(10004, "smallMapRegion1", 301, 68, 22, 110, Language.getString(21311)), new SmallMapWorldRegionData(10005, "smallMapRegion1", 167, 37, 16, 78, Language.getString(21312)), new SmallMapWorldRegionData(10006, "smallMapRegion1", 129, 138, -6, 93, Language.getString(21313)), new SmallMapWorldRegionData(10007, "smallMapRegion1", 91, 240, 6, 130, Language.getString(21314), true, 90), new SmallMapWorldRegionData(10008, "smallMapRegion1", 13, 32, 14, 102, Language.getString(21315), true, 100), new SmallMapWorldRegionData(10100, "smallMapRegion1", 501, 21, 30, 81, Language.getString(21316))];
            this.allRegions = [this.regionDatas_0];
            this._paths = [];
            return;
        }// end function

        public function getRightTopShowTypes() : Array
        {
            if (this.showTypes == null)
            {
                this.showTypes = [];
                this.showTypes.push(this.myShowTypes[0]);
                this.showTypes.push(this.myShowTypes[1]);
                this.showTypes.push(this.myShowTypes[2]);
                this.showTypes.push({icon:ImagesConst.MapPoint_Self2, name:Language.getString(21304), type:SmallMapShowType.MapShowTypeSelf});
                this.showTypes.push({icon:ImagesConst.MapPoint_Teamate, name:Language.getString(21305), type:SmallMapShowType.MapShowType_Teamate});
                this.showTypes.push(this.myShowTypes[7]);
            }
            return this.showTypes;
        }// end function

        public function set allEntityPoints(param1:Array) : void
        {
            this._allForceEntityPoints = param1;
            return;
        }// end function

        public function set shortMapEntitys(param1:Array) : void
        {
            this._shortMapEntitys = param1;
            return;
        }// end function

        public function get paths() : Array
        {
            if (this._paths == null)
            {
                this._paths = [];
            }
            return this._paths;
        }// end function

        public function set paths(param1:Array) : void
        {
            this._lastFisrtDistance = 1000000;
            this._paths = param1;
            Dispatcher.dispatchEvent(new DataEvent(EventName.SmallMapPathChanged, this._paths));
            return;
        }// end function

        public function getRegionDataByMapId(param1:int) : Array
        {
            var _loc_2:Array = null;
            var _loc_3:SmallMapWorldRegionData = null;
            return this.regionDatas_0;
            return [];
        }// end function

        private function getMapRelationId(param1:int) : int
        {
            if (MapRegionRelationConst[param1.toString()] != null)
            {
                return int(MapRegionRelationConst[param1.toString()]);
            }
            return param1;
        }// end function

        public function fixPathPoint(param1:Boolean = false) : void
        {
            var _loc_8:Point = null;
            var _loc_9:Number = NaN;
            if (this._paths == null || this._paths.length == 0)
            {
                return;
            }
            if (param1)
            {
                this._paths.splice(0, 1);
                return;
            }
            var _loc_2:* = GameMapUtil.tileWidth;
            var _loc_3:* = GameMapUtil.tileHeight;
            var _loc_4:* = PetBreakCopyUtil.player;
            var _loc_5:* = GameMapUtil.getTilePoint(_loc_4.x2d, _loc_4.y2d);
            _loc_5.x = _loc_5.x + 0.5;
            _loc_5.y = _loc_5.y + 0.5;
            var _loc_6:Boolean = false;
            var _loc_7:int = 0;
            while (_loc_7 < this._paths.length)
            {
                
                _loc_8 = this._paths[_loc_7];
                _loc_9 = GeomUtil.calcDistance(_loc_5.x * _loc_2, _loc_5.y * _loc_3, _loc_8.x * _loc_2, _loc_8.y * _loc_3);
                if (_loc_9 <= 10)
                {
                    this._paths.splice(0, (_loc_7 + 1));
                    return;
                }
                if (_loc_7 == 0)
                {
                    if (_loc_9 > this._lastFisrtDistance)
                    {
                        this._lastFisrtDistance = 10000000;
                        _loc_6 = true;
                    }
                    else
                    {
                        this._lastFisrtDistance = _loc_9;
                    }
                }
                _loc_7++;
            }
            if (_loc_6)
            {
                this._paths.splice(0, 1);
            }
            return;
        }// end function

        public function clearPaths() : void
        {
            this._lastFisrtDistance = 1000000;
            this._paths = [];
            return;
        }// end function

        public function getDataByType(param1:int, param2:int) : Array
        {
            var _loc_3:Array = [];
            var _loc_4:* = SceneConfig.instance.getSceneInfo(param2);
            var _loc_5:* = this.getObjByType(param1);
            switch(param1)
            {
                case SmallMapShowType.MapShowTypePassPoint:
                {
                    _loc_3 = this.getPassPoint(_loc_3, _loc_5, _loc_4);
                    break;
                }
                case SmallMapShowType.MapShowTypeBoss:
                {
                    _loc_3 = this.getBoss(_loc_3, _loc_5, _loc_4);
                    break;
                }
                case SmallMapShowType.MapShowTypeTaskNpc:
                {
                    _loc_3 = this.getNPc(_loc_3, _loc_5, _loc_4, SmallMapShowType.MapShowTypeTaskNpc);
                    break;
                }
                case SmallMapShowType.MapShowTypeTaskEScort:
                {
                    _loc_3 = this.getNPc(_loc_3, _loc_5, _loc_4, SmallMapShowType.MapShowTypeTaskEScort);
                    break;
                }
                case SmallMapShowType.MapShowTypeTaskLoop:
                {
                    _loc_3 = this.getNPc(_loc_3, _loc_5, _loc_4, SmallMapShowType.MapShowTypeTaskLoop);
                    break;
                }
                case SmallMapShowType.MapShowTypeTaskLueMo:
                {
                    _loc_3 = this.getNPc(_loc_3, _loc_5, _loc_4, SmallMapShowType.MapShowTypeTaskLueMo);
                    break;
                }
                case SmallMapShowType.MapShowTypeTaskMining:
                {
                    _loc_3 = this.getNPc(_loc_3, _loc_5, _loc_4, SmallMapShowType.MapShowTypeTaskMining);
                    break;
                }
                case SmallMapShowType.MapShowTypeChangeCareer:
                {
                    _loc_3 = this.getNPc(_loc_3, _loc_5, _loc_4, SmallMapShowType.MapShowTypeChangeCareer);
                    break;
                }
                case SmallMapShowType.MapShowtypeJumpPoint:
                {
                    _loc_3 = this.getJumpPoint(_loc_3, _loc_5, _loc_4);
                    break;
                }
                case SmallMapShowType.MapShowType_Teamate:
                {
                    _loc_3 = this.getTeamates();
                }
                default:
                {
                    break;
                }
            }
            return _loc_3;
        }// end function

        private function getJumpPoint(param1:Array, param2:Object, param3:SceneInfo) : Array
        {
            var _loc_5:SPoint = null;
            var _loc_6:SmallMapTypeIconData = null;
            var _loc_4:* = param3.jumpPoints;
            for each (_loc_5 in _loc_4)
            {
                
                _loc_6 = new SmallMapTypeIconData();
                _loc_6.x = _loc_5.x;
                _loc_6.y = _loc_5.y;
                _loc_6.iconName = param2["icon"];
                _loc_6.type = param2["type"];
                _loc_6.name = Language.getString(21317);
                _loc_6.tips = Language.getString(21317);
                _loc_6.value = param3.sMapDefine.mapId;
                param1.push(_loc_6);
            }
            return param1;
        }// end function

        public function getAllChangabelDatas() : Array
        {
            var _loc_3:ISMallMapTyperIconDataParser = null;
            var _loc_4:Dictionary = null;
            var _loc_5:IEntity = null;
            var _loc_6:ISmallMapShortMapEntityParser = null;
            var _loc_7:Array = null;
            var _loc_8:SShortMapEntity = null;
            var _loc_1:Array = [];
            var _loc_2:* = this.getTypeIconDataParser();
            if (_loc_2 is ISMallMapTyperIconDataParser)
            {
                _loc_3 = _loc_2 as ISMallMapTyperIconDataParser;
                _loc_4 = ThingUtil.entityUtil.entitysMap.allEntitys;
                for each (_loc_5 in _loc_4)
                {
                    
                    _loc_3.chooseIcon(_loc_5, _loc_1);
                }
            }
            else if (_loc_2 is ISmallMapShortMapEntityParser)
            {
                _loc_6 = _loc_2 as ISmallMapShortMapEntityParser;
                _loc_7 = this._shortMapEntitys;
                for each (_loc_8 in _loc_7)
                {
                    
                    _loc_6.mortal.game.view.mainUI.smallMap.view.typeIconDataParser:ISmallMapShortMapEntityParser::chooseIcon(_loc_8, _loc_1);
                }
            }
            return _loc_1;
        }// end function

        public function getTeamates() : Array
        {
            var _loc_4:SGroupPlayer = null;
            var _loc_5:SmallMapTypeIconData = null;
            var _loc_1:Array = [];
            var _loc_2:* = Cache.instance.group.players;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                _loc_4 = _loc_2[_loc_3] as SGroupPlayer;
                if (_loc_4.player.entityId.id == Cache.instance.role.roleEntityInfo.entityInfo.entityId.id)
                {
                }
                else if (Game.mapInfo != null && _loc_4.player.mapId != Game.mapInfo.mapId)
                {
                }
                else if (_loc_4.point.x <= 0 && _loc_4.point.y <= 0)
                {
                }
                else
                {
                    _loc_5 = new SmallMapTypeIconData();
                    _loc_5.x = _loc_4.point.x;
                    _loc_5.y = _loc_4.point.y;
                    _loc_5.name = "<font color=\'#00ff00\'>" + _loc_4.player.name + "</font>";
                    _loc_5.tips = _loc_4.player.name;
                    _loc_5.type = SmallMapShowType.MapShowType_Teamate;
                    _loc_5.iconName = "smallMapTeamate.swf";
                    _loc_5.width = 0;
                    _loc_5.height = 0;
                    _loc_1.push(_loc_5);
                }
                _loc_3++;
            }
            return _loc_1;
        }// end function

        private function getTypeIconDataParser()
        {
            if (CopyUtil.isInDefenseCopy || CopyUtil.isInZZXYBattleCopy)
            {
                return SmallMap_DefenceCopyParser.instance;
            }
            if (CopyUtil.isInTeamDefenseCopy)
            {
                return SmallMap_TeamDefenceCopyParse.instance;
            }
            if (GameMapUtil.curMapState.isEscortCopy)
            {
                return SmallMap_EscortCopyParser.instance;
            }
            if (GameMapUtil.curMapState.isBattlefield)
            {
                return SmallMap_BattleFiledParser.instance;
            }
            if (GameMapUtil.curMapState.isGuildWar)
            {
                return SmallMap_GuildWarParser.instance;
            }
            if (CopyUtil.isInAllEscortTask)
            {
                return SmallMap_EscortParser.instance;
            }
            if (GameMapUtil.curMapState.isCrossMap)
            {
                return SmallMap_ArenaParser.instance;
            }
            if (GameMapUtil.curMapState.isArenaCopy)
            {
                return SmallMap_ArenaParser.instance;
            }
            if (GameMapUtil.curMapState.isTreasureHunt)
            {
                return SmallMap_TreasureHuntParser.instance;
            }
            if (CopyUtil.isInGuildDefenseCopy)
            {
                return SmallMap_GuildDefenseCopy.instance;
            }
            if (CopyUtil.isInMainCityBattleFinalCopy || CopyUtil.isInMainCityBattleKOCopy)
            {
                return SmallMap_MainCityBattleParser.instance;
            }
            return SmallMap_NormalParser.instance;
        }// end function

        public function initCustomMapPoints(param1:Array) : void
        {
            var _loc_2:SCustomPoint = null;
            var _loc_3:int = 0;
            var _loc_4:SmallMapCustomXYData = null;
            this._customMapPointDatas = [];
            for each (_loc_2 in param1)
            {
                
                this.addCustomMapPoint(_loc_2);
            }
            _loc_3 = 0;
            while (_loc_3 < 5)
            {
                
                if (this._customMapPointDatas[_loc_3] != null)
                {
                }
                else
                {
                    _loc_4 = new SmallMapCustomXYData();
                    this._customMapPointDatas[_loc_3] = _loc_4;
                    _loc_4.index = _loc_3;
                    _loc_4.name = Language.getStringByParam(20080, (_loc_3 + 1));
                    _loc_4.mapName = Language.getString(20082);
                    _loc_4.isNotSet = true;
                    _loc_4.x = 0;
                    _loc_4.y = 0;
                    _loc_4.mapId = 0;
                }
                _loc_3++;
            }
            return;
        }// end function

        public function addCustomMapPoint(param1:SCustomPoint) : void
        {
            var _loc_2:* = new SmallMapCustomXYData();
            this._customMapPointDatas[param1.index] = _loc_2;
            _loc_2.index = param1.index;
            _loc_2.name = param1.name;
            _loc_2.isNotSet = false;
            _loc_2.x = param1.point.x;
            _loc_2.y = param1.point.y;
            _loc_2.mapId = param1.mapId;
            var _loc_3:* = GameMapConfig.instance.getMapInfo(param1.mapId);
            if (_loc_3 != null)
            {
                _loc_2.mapName = _loc_3.name;
            }
            else
            {
                _loc_2.mapName = "";
            }
            return;
        }// end function

        public function get customMapPointData() : DataProvider
        {
            var _loc_3:SmallMapCustomXYData = null;
            var _loc_1:* = new DataProvider();
            var _loc_2:int = 0;
            while (_loc_2 < 5)
            {
                
                _loc_3 = this._customMapPointDatas[_loc_2];
                _loc_1.addItem(_loc_3);
                _loc_2++;
            }
            return _loc_1;
        }// end function

        public function get customMapPointArr() : Array
        {
            return this._customMapPointDatas;
        }// end function

        private function getPassPoint(param1:Array, param2:Object, param3:SceneInfo) : Array
        {
            var _loc_5:SPassPoint = null;
            var _loc_6:SmallMapTypeIconData = null;
            var _loc_4:* = param3.passInfos;
            for each (_loc_5 in _loc_4)
            {
                
                if (ThingUtil.passUtil.isAddToStage(_loc_5))
                {
                    _loc_6 = new SmallMapTypeIconData();
                    _loc_6.x = _loc_5.point.x;
                    _loc_6.y = _loc_5.point.y;
                    _loc_6.value = _loc_5;
                    _loc_6.name = _loc_5.name;
                    _loc_6.iconName = "guidePassPoing.swf";
                    _loc_6.width = 0;
                    _loc_6.height = 0;
                    _loc_6.type = param2["type"];
                    if (_loc_5.passTo != null && _loc_5.passTo.length > 0)
                    {
                        _loc_6.tips = Language.getStringByParam(20072, _loc_5.passTo[0]["name"]);
                    }
                    else
                    {
                        _loc_6.tips = Language.getString(21318);
                    }
                    param1.push(_loc_6);
                }
            }
            return param1;
        }// end function

        private function getBoss(param1:Array, param2:Object, param3:SceneInfo) : Array
        {
            var _loc_5:BossRefreshInfo = null;
            var _loc_6:SmallMapTypeIconData = null;
            var _loc_7:TBossRefresh = null;
            var _loc_8:TBoss = null;
            var _loc_4:* = param3.bossRefreshs;
            for each (_loc_5 in _loc_4)
            {
                
                _loc_6 = new SmallMapTypeIconData();
                _loc_6.x = _loc_5.x;
                _loc_6.y = _loc_5.y;
                _loc_6.value = 0;
                _loc_7 = _loc_5.bossRefreshs[0] as TBossRefresh;
                _loc_6.iconName = param2["icon"];
                if (_loc_7 != null)
                {
                    _loc_8 = BossConfig.instance.getInfoByCode(_loc_7.bossCode);
                    if (_loc_8 != null)
                    {
                        _loc_6.name = _loc_8.name + "[" + _loc_8.level + "]";
                        _loc_6.tips = _loc_8.name;
                    }
                    else
                    {
                        _loc_6.name = "boss[1]";
                        _loc_6.tips = "boss[1]";
                    }
                    if (_loc_5.subPoints != null && _loc_5.subPoints != "" && _loc_5.subPoints.length <= 3)
                    {
                        _loc_6.iconName = "BossDrop_" + _loc_5.subPoints;
                        _loc_6.tips = this._dropName[int(_loc_5.subPoints)];
                    }
                }
                else
                {
                    continue;
                }
                if (Cache.instance.autoFight.isBossPointKilled(_loc_5.x, _loc_5.y) && CopyUtil.isShowBossKilledMap)
                {
                    _loc_6.isGrayFilter = true;
                    _loc_6.tips = _loc_6.tips + "(已击杀)";
                }
                else
                {
                    _loc_6.isGrayFilter = false;
                }
                _loc_6.type = param2["type"];
                param1.push(_loc_6);
            }
            return param1;
        }// end function

        private function getNPc(param1:Array, param2:Object, param3:SceneInfo, param4:int) : Array
        {
            var _loc_6:NPCInfo = null;
            var _loc_7:SmallMapTypeIconData = null;
            var _loc_5:* = param3.npcInfos;
            for each (_loc_6 in _loc_5)
            {
                
                if (_loc_6.tnpc.type != param4)
                {
                    continue;
                }
                if (_loc_6.snpc.notShowInMap > 0)
                {
                    continue;
                }
                _loc_7 = new SmallMapTypeIconData();
                _loc_7.name = _loc_6.snpc.name;
                _loc_7.value = _loc_6.snpc.npcId;
                _loc_7.x = _loc_6.snpc.point.x;
                _loc_7.y = _loc_6.snpc.point.y;
                _loc_7.tips = _loc_6.snpc.name;
                _loc_7.iconName = param2["icon"];
                _loc_7.type = param2["type"];
                if (_loc_7.name == null)
                {
                    continue;
                }
                param1.push(_loc_7);
            }
            return param1;
        }// end function

        private function getObjByType(param1:int) : Object
        {
            var _loc_2:Object = null;
            for each (_loc_2 in this.myShowTypes)
            {
                
                if (_loc_2["type"] == param1)
                {
                    return _loc_2;
                }
            }
            return null;
        }// end function

    }
}
